//package com.koicarp.university.graduate.auth.handle;
//
//import com.koicarp.university.graudate.common.constant.BaseConstant;
//import com.koicarp.university.graudate.common.utils.UniversityResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.oauth2.common.OAuth2AccessToken;
//import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.security.Principal;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @auther liutao
// * @Date 2020-09-01 08:35:29
// */
//@Component
//public class SuccessAuthHandler implements AuthenticationSuccessHandler {
//
//    @Autowired
//    private TokenEndpoint tokenEndpoint;
//    @Autowired
//    private Principal principal;
//    @Override
//    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
//        String username = httpServletRequest.getParameter("username");
//        String password = httpServletRequest.getParameter("password");
//        String client_id = httpServletRequest.getParameter("client_id");
//        String client_secret = httpServletRequest.getParameter("client_secret");
//        String grant_type = httpServletRequest.getParameter("grant_type");
//        String scope = httpServletRequest.getParameter("scope");
//        Map<String,String> map=new HashMap<>();
//        map.put("username",username);
//        map.put("client_id",client_id);
//        map.put("client_secret",client_secret);
//        map.put("grant_type",grant_type);
//        map.put("scope",scope);
//
//        OAuth2AccessToken token= (OAuth2AccessToken) tokenEndpoint.postAccessToken(principal,map);
//        UniversityResponse response=new UniversityResponse();
//        httpServletResponse.setContentType("text/html;charset=utf-8");
//        response.code(BaseConstant.RESPONSE_CODE_SUCCESS_200);
//        response.data(token);
//        PrintWriter out =httpServletResponse.getWriter();
//        out.append(response.toString());
//    }
//}
